import 'package:asset_delivery/asset_delivery_platform_interface.dart';
import 'package:flutter/material.dart';
import 'package:asset_delivery/asset_delivery.dart';
import 'dart:convert';
void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  var jsonEncoder = const JsonEncoder.withIndent('  ');
  var assetPackName='asset_model';
  String info='';
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: Column(
              children: [
                ElevatedButton(
                  onPressed: () async {
                    AssetDelivery.getAssetPackStatus((map){
                      debugPrint('AssetPackStatus:');
                      debugPrint(jsonEncoder.convert(map));
                    });
                    var state=AssetDelivery.fetchAssetPackState(assetPackName);
                    debugPrint('fetchAssetPackState(before):$state');
                    await AssetDelivery.fetch(assetPackName);
                    state=AssetDelivery.fetchAssetPackState(assetPackName);
                    debugPrint('fetchAssetPackState(after):$state');
                    String path=await AssetDelivery.getAssetPackPath(assetPackName: assetPackName, count: 1, namingPattern: '0', fileExtension: 'pdf') ?? '';
                    setState(() {
                      info=path;
                    });
                  },
                  child: const Text('点击我'),
                ),
                const SizedBox(
                  height: 10,
                ),
                Text(info),
              ],
            )
          // Example app link : https://github.com/mohsen-motlagh/asset_delivery_example
        ),
      ),
    );
  }
}
